
import { request } from '../../request/index.js'
import { login } from '../../utils/asyncWx.js'
import regeneratorRuntime from '../../lib/runtime/runtime.js'

Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  },
  // 获取用户信息
  async handleGetUserInfo(e) {
    try {
      const { encryptedData, rawData, iv, signature } = e.detail
      const { code } = await login()
      const loginParams = { encryptedData, rawData, iv, signature, code }
      if (loginParams) {
        let taken = "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo"
        wx.setStorageSync("taken", taken);
      } else {
        await showToast({ title: "授权失败！" })
      }
      wx.navigateBack({
        delta: 1
      });
    } catch (error) {
      console.log(error)
    }
    // const res = await request({ url: '/users/wxlogin', data: loginParams, methods: 'post' })
  }
})